package cn.jinjimi.app.modules.Theme;

import com.google.gson.annotations.SerializedName;
import cn.jinjimi.base.util.GsonUtils;
import cn.jinjimi.app.entity.AppConfig.AppModule;
import cn.jinjimi.app.managers.ConfigManager;
import cn.jinjimi.app.modules.IModule;

/**
 * Created by Roy
 * Date: 2017/3/27
 */

public class ZdbTheme implements IModule<ZdbTheme.Config> {

    private static volatile ZdbTheme mInstance = null;
    private ZdbTheme.Config mConfig;

    public static ZdbTheme getInstance() {
        if (mInstance == null) {
            synchronized (ZdbTheme.class) {
                if (mInstance == null) {
                    mInstance = new ZdbTheme();
                }
            }
        }
        return mInstance;
    }

    @Override
    public Config getConfig() {
        if (mConfig == null) {
            String data = ConfigManager.getInstance().getConfig(AppModule.ModuleTheme);
            mConfig = GsonUtils.fromJson(data, ZdbTheme.Config.class);
        }
        return mConfig;
    }

    public ZdbTheme.Config createConfig() {
        String data = ConfigManager.getInstance().getConfig(AppModule.ModuleTheme);
        mConfig = GsonUtils.fromJson(data, ZdbTheme.Config.class);
        return mConfig;
    }

    public static class Config {

        /* 主题color文件MD5码 */
        @SerializedName("md5")
        public String md5;

        /* 主题color文件下载地址 */
        @SerializedName("src")
        public String src;
    }
}
